//
//  TuPianViewController.m
//  DianDangDai
//
//  Created by bhf on 2017/12/25.
//  Copyright © 2017年 bhf. All rights reserved.
//

#import "TuPianViewController.h"

@interface TuPianViewController ()<WKNavigationDelegate,WKUIDelegate>

@end

@implementation TuPianViewController

- (void)viewWillAppear:(BOOL)animated {
    
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:NO animated:YES];
}


- (void)viewDidLoad {
    [super viewDidLoad];
    
    if (@available(iOS 11.0, *)) {
        self.MyWeb.scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    } else {
        self.automaticallyAdjustsScrollViewInsets = NO;
        // Fallback on earlier versions
    }

    NSLog(@"%@",_titleStr);
    self.MyWeb = [[WKWebView alloc] initWithFrame:CGRectMake(0, 64, self.view.frame.size.width, self.view.frame.size.height-64)];
    self.MyWeb.navigationDelegate = self;
    self.MyWeb.UIDelegate = self;
    //self.MyWeb.scrollView.pagingEnabled = YES;
    self.MyWeb.scrollView.scrollsToTop = NO;
    self.MyWeb.scrollView.bounces = NO;
    
    [self.view addSubview:self.MyWeb];
    if (@available(iOS 9.0, *)) {
        NSString *urlstring = [NSString stringWithFormat:@"http://apitest.diandangdai.com/app/servicesWs?OPT=1038&sign=37FA804546A247A9E4D765AF10575A45D006E636070F4B8A2A9349E9FC2ADB91d8bf785b"];
        NSLog(@"%@",urlstring);
        NSURL *url = [NSURL URLWithString:urlstring];
        
        NSURLRequest *request = [NSURLRequest requestWithURL:url];
        [self.MyWeb loadRequest:request];
        [MBProgressHUD showHUD];
    } else {
        // Fallback on earlier versions
    }
    // Do any additional setup after loading the view.
}

- (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation {
    [MBProgressHUD dissmiss];
}

- (void)webView:(WKWebView *)webView didFailProvisionalNavigation:(WKNavigation *)navigation{
    
    ZCAlertViewController *alert = [ZCAlertViewController alertControllerWithTitle:@"提示" message:@"加载失败，是否重新加载"];
    ZCAlertAction *action = [ZCAlertAction actionWithTitle:@"确定" handler:^(ZCAlertAction *action) {
        [self.MyWeb reload];
        [MBProgressHUD showHUD];
    }];
    ZCAlertAction *cancel = [ZCAlertAction actionWithTitle:@"取消" handler:^(ZCAlertAction *action) {
        
    }];
    [alert addAction:action];
    [alert addAction:cancel];
    [self presentViewController:alert animated:NO completion:nil];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
